#!/bin/sh

# Slackware build script for atol
# Written by Erik Hanson  erik@slackbuilds.org

# Modified by the SlackBuilds.org project

PRGNAM=atol
VERSION=0.7.3
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=`pwd`
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP || exit 1
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-${VERSION}_src.tar.gz || exit 1
cd $PRGNAM-$VERSION || exit 1
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# Makefile has to be patched either way.
if $(pkg-config --exists gnome-vfs-2.0); then
  echo "GNOME-VFS Found"
  patch -p0 < $CWD/gvfs.Makefile.diff || exit 1
elif ! $(pkg-config --exists gnome-vfs-2.0); then
  echo "GNOME-VFS Not Found"
  patch -p0 < $CWD/no-gvfs.Makefile.diff || exit 1
fi

make || exit 1
make install DESTDIR=$PKG || exit 1

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

# Fix the icon path in the desktop file
sed -i 's%Icon=atol.xpm%Icon=/usr/share/icons/atol.xpm%' \
  $PKG/usr/share/applications/atol.desktop || exit 1

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a readme.txt docs/license.txt $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n -p $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
